package al.softsynergy.auk.ui.utils;

import al.softsynergy.auk.data.entries.AnkesaLloj;

import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.Label;
import com.vaadin.ui.Table;
import com.vaadin.ui.Table.ColumnGenerator;

public class ColumnGeneratorUtils {

	
	public static ColumnGenerator ankesaLlojColumnGenerator(){
		
		return new ColumnGenerator() {
			
			@Override
			public Component generateCell(Table source, Object itemId, Object columnId) {
				final Label l = new Label();
				final Property val = source.getContainerProperty(itemId,columnId);
				if (val.getValue() != null)
					l.setValue(((AnkesaLloj)val.getValue()).getTag());
				else
					l.setValue("");
				
				if (val instanceof Property.ValueChangeNotifier) {
				Property.ValueChangeNotifier notifier = (Property.ValueChangeNotifier) val;
				notifier.addListener(new ValueChangeListener() {

					@Override
					public void valueChange(
							com.vaadin.data.Property.ValueChangeEvent event) {
						if (val.getValue() != null)
							l.setValue(((AnkesaLloj)val.getValue()).getTag());
						else
							l.setValue("");
						
							
						
					}});
				}
				return l;
			}
		};
	}
	

	

}
